const axios = require("axios");
/**
 * api 来源：https://jsonplaceholder.typicode.com/guide/
 */
/**
 * 新增用户api
 * @param userId
 * @returns {Promise<AxiosResponse<any>>}
 */
module.exports.addUser = (userId) => {
    return axios.post("https://jsonplaceholder.typicode.com/posts", {
        title: '燕燕',
        body: '小可爱学java',
        userId: userId,
    })
}

/**
 * 查看用户
 * @param userId
 * @returns {Promise<AxiosResponse<any>>}
 */
module.exports.getUserById = function (userId) {
    return axios.get("https://jsonplaceholder.typicode.com/posts/" + userId)
}

/**
 * 用户列表
 * @returns {Promise<AxiosResponse<any>>}
 */
module.exports.listUser = function () {
    return axios.get("https://jsonplaceholder.typicode.com/posts")
}

/**
 * 删除用户api
 * @param id
 * @returns {Promise<AxiosResponse<any>>}
 */
function deleteUser(id) {
    return axios.delete("https://jsonplaceholder.typicode.com/posts/" + id)
}

module.exports.deleteUser = deleteUser
